package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.common.utils.MinioTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @Author: wuxuan
 * @Date: 2023/03/17
 * @Description: 文件处理接口
 */
@RestController
@RequestMapping("/client/file")
@Api(tags = "(客户端) 文件处理接口")
public class SysFileController {
    @Autowired
    private MinioTemplate minioTemplate;

    @PostMapping("/upload")
    @ApiOperation(value = "文件上传")
    public ResultEntity upload(@RequestParam("file") MultipartFile file) throws Exception {
        return ResultEntity.createSuccess(minioTemplate.upload(file));
    }

    @GetMapping("/download")
    @ApiOperation(value = "文件下载")
    public ResultEntity download(@RequestParam(value = "path")String filePath){
        System.out.println("--------------- 文件下载开始  ----------------");
        return ResultEntity.createSuccess(minioTemplate.downloadBase64(filePath));
    }

}
